package com.tjtt.gwm.dao.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.tjtt.gwm.dao.GuanxianDao;
import com.tjtt.gwm.dao.SearchDao;
import com.tjtt.gwm.service.DbService;
import com.tjtt.tdm.base.BaseHibernateDao;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.base.StringUtil;

public class GuanxianDaoImpl extends BaseHibernateDao implements GuanxianDao {
	private DbService dbService;
	public PageResult queryTezhengdlist(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from ptem_pipepoint t  where 1=1");
		queryString.append("select t.ID,T.POINTNO,T.POINTNAME,T.GROUNDMARK,T.LOCATIONY,T.LOCATIONX," +
				"T.HEIGHT,T.LONGITUDE,T.LATITUDE,T.ELLIPSOIDH,T.REMARK,T.PIPELINENO,T.PIPESECTIONNO," +
				"T.SIGNEDUNIT,T.SIGNED from ptem_pipepoint t  where 1=1 ");
//		queryString.append(" and t.POINTNO = '"+filterMap.get("tzid")+"'");
//		countString.append(" and t.POINTNO = '"+filterMap.get("tzid")+"'");
		queryString.append(" and t.pipelineno = '"+filterMap.get("tzid")+"'");
		countString.append(" and t.pipelineno = '"+filterMap.get("tzid")+"'");
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public PageResult queryPointTeeList(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from ptem_point_tee t  where 1=1");
//		queryString.append("select t.ID,T.POINTNO,T.POINTNAME,T.GROUNDMARK,T.LOCATIONY,T.LOCATIONX," +
//				"T.HEIGHT,T.LONGITUDE,T.LATITUDE,T.ELLIPSOIDH,T.REMARK,T.PIPELINENO,T.PIPESECTIONNO," +
//				"T.SIGNEDUNIT,T.SIGNED from ptem_pipepoint t  where 1=1 ");
		queryString.append("select t.ID,T.TEENO,T.LOCATIONY,T.LOCATIONX,T.HEIGHT," +
				"T.LONGITUDE,T.LATITUDE,T.ELLIPSEH,T.TYPE,T.MAINTHICKNESS,T.MAINDIAMETER," +
				"T.BRANCHTHICKNESS,T.BRANCHDIAMETER,T.PRESSURELEVEL,T.REMARK," +
				"T.PIPELINENO,T.PIPESECTIONNO,T.ATTACHMENT,T.SIGNEDUNIT,T.SIGNED" +
				" from ptem_point_tee T  where 1=1 ");

		queryString.append(" and t.pipelineno = '"+filterMap.get("tzid")+"'");
		countString.append(" and t.pipelineno = '"+filterMap.get("tzid")+"'");
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public boolean IsConValInRange(double conVal,String rfieldvalue1,
			String rfieldvalue2,String rlimit1,String rlimit2)
	{
		double rValue1=0;	
		double rValue2=0;
		if(rfieldvalue1!="")
		{
			rValue1=Double.parseDouble(rfieldvalue1);
		}
		if(rfieldvalue2!="")
		{
			rValue2=Double.parseDouble(rfieldvalue2);
		}
		boolean bool=false;
		boolean bool1 = true;
		boolean bool2 = true;
		if(rlimit1.equals("<"))
		{
			bool1=conVal<rValue1;
		}
		if(rlimit1.equals("<="))
		{
			bool1=conVal<=rValue1;
		}
		if(rlimit2.equals(">")){
			bool2=conVal>rValue2;
		}
		if(rlimit2.equals(">=")){
			bool2=conVal>=rValue2;
		}
		bool=bool1&&bool2;
		return bool;
	}
	
	public List<String> getListByAutosearchRangeMulti(String rfieldname,
			String rfieldvalue1,String rlimit1,String rfieldvalue2,
			String rlimit2,String owner) throws IOException{
		List<String> guanxianlists=new ArrayList<String>();
		String strSql="select t.QUERY_TABLE,t.QUERY_FIELD," +
		"t.CONDITION_TABLE,t.CONDITION_FIELD_EN," +
		"MAIN_FIELD,FOREIGN_FIELD from PTEM_SEARCH_RANGE t " +
		//"where t.CONDITION_FIELD_EN='"+rfieldname+
		"where t.CONDITION_FIELD_CN='"+rfieldname+
		"'and t.OWNER='"+owner+"'";
		List<Object[]> objs=dbService.queryDataBySql(strSql);
		if(objs.size()==0)
		{
			return null;
		}
		Object[] obj=new Object[6];
		String query_table="";
		String query_field="";
		String condition_table="";
		String condition_field_en="";
		String main_field="";
		String foreign_field="";
		obj=objs.get(0);
		if(obj[0]!=null)
		{
			query_table=obj[0].toString();
		}
		if(obj[1]!=null)
		{
			query_field=obj[1].toString();
		}
		if(obj[2]!=null)
		{
			condition_table=obj[2].toString();
		}
		if(obj[3]!=null)
		{
			condition_field_en=obj[3].toString();
		}	
		if(obj[4]!=null)
		{
			main_field=obj[4].toString();
		}
		if(obj[5]!=null)
		{
			foreign_field=obj[5].toString();
		}
		if(main_field.equals("")||foreign_field.equals("")) //同一表中查询
		{
			strSql="select "+query_field+","+condition_field_en+" from "+query_table+
			" t where t."+condition_field_en+" is not null";
			List<Object[]> listAll= dbService.queryDataBySql(strSql);
			int num=listAll.size();			
			for(int i=0;i<num;i++)
			{
				Object objT[]=listAll.get(i);
				String query_field_val=objT[0].toString();
				String condition_field_enVal=objT[1].toString();
				//是否为多个值
				String conValArr[]=condition_field_enVal.split("；");
				int valNum=conValArr.length;
				int j=0;
				for(j=0;j<valNum;j++)
				{
					double conVal=Double.parseDouble(conValArr[j]);
					boolean bool=IsConValInRange(conVal,rfieldvalue1,rfieldvalue2,rlimit1,rlimit2);
					if(bool==true)
					{
						break;
					}
				}
				if(j<valNum)
				{
					guanxianlists.add(query_field_val);
				}
			}							
		}
		else  //不同表中查询
		{
			List<String> list = null;
			strSql="select t2."+main_field+",t2."+condition_field_en+
			" from "+condition_table+" t2 ";
			List<Object[]> listAll= dbService.queryDataBySql(strSql);
			int num=listAll.size();			
			for(int i=0;i<num;i++)
			{
				Object objT[]=listAll.get(i);
				String query_field_val=objT[0].toString();
				String condition_field_enVal=objT[1].toString();
				//是否为多个值
				String conValArr[]=condition_field_enVal.split("；");
				int valNum=conValArr.length;
				int j=0;
				for(j=0;j<valNum;j++)
				{
					double conVal=Double.parseDouble(conValArr[j]);
					boolean bool=IsConValInRange(conVal,rfieldvalue1,rfieldvalue2,rlimit1,rlimit2);
					if(bool==true)
					{
						break;
					}
				}
				if(j<valNum)
				{
					list.add(query_field_val);
				}
			}							
			int size=list.size();
			if(size==0)
			{
				return null;
			}
			List<String> resultList=new ArrayList();
			for(int i=0;i<size;i++)
			{
				String result=list.get(i);
				String[] fieldValue=result.split("；");
				int numValue=fieldValue.length;
				for(int j=0;j<numValue;j++)
				{
					String str=fieldValue[j];
					resultList.add(str);
				}
			}			
			strSql="select "+query_field+" from "+query_table+" t1 where t1."+
			foreign_field+" in(";
			int numResult=resultList.size();
			for(int k=0;k<numResult;k++)
			{
				strSql+="'"+resultList.get(k)+"',";
			}
			strSql=strSql.substring(0,strSql.length()-1);
			strSql+=")";
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		return guanxianlists;
		//if(query_table.equals("PTEM_TEST_TASK")) //表1 检验检测任务表中的一条记录的多个管线以“；”分隔。
		//{
		//	guanxianlists=splitPipeLine(guanxianlists);
		//}
	}
	
	public List<String> getListByAutosearchRange(String rfieldname,
			String rfieldvalue1,String rlimit1,String rfieldvalue2,
			String rlimit2,String owner) throws IOException{
		List<String> guanxianlists=null;
		String strSql="select t.QUERY_TABLE,t.QUERY_FIELD," +
		"t.CONDITION_TABLE,t.CONDITION_FIELD_EN," +
		"MAIN_FIELD,FOREIGN_FIELD from PTEM_SEARCH_RANGE t " +
		//"where t.CONDITION_FIELD_EN='"+rfieldname+
		"where t.CONDITION_FIELD_CN='"+rfieldname+
		"'and t.OWNER='"+owner+"'";
		List<Object[]> objs=dbService.queryDataBySql(strSql);
		if(objs.size()==0)
		{
			return null;
		}
		Object[] obj=new Object[6];
		String query_table="";
		String query_field="";
		String condition_table="";
		String condition_field_en="";
		String main_field="";
		String foreign_field="";
		obj=objs.get(0);
		if(obj[0]!=null)
		{
			query_table=obj[0].toString();
		}
		if(obj[1]!=null)
		{
			query_field=obj[1].toString();
		}
		if(obj[2]!=null)
		{
			condition_table=obj[2].toString();
		}
		if(obj[3]!=null)
		{
			condition_field_en=obj[3].toString();
		}	
		if(obj[4]!=null)
		{
			main_field=obj[4].toString();
		}
		if(obj[5]!=null)
		{
			foreign_field=obj[5].toString();
		}
		if(main_field.equals("")||foreign_field.equals(""))
		{
			if((rfieldvalue1!=""&rlimit1!="")&(rfieldvalue2!=""&rlimit2!=""))
			{
				strSql="select "+query_field+" from "+query_table+" t where t."+
				condition_field_en+rlimit1+rfieldvalue1+" and t."+condition_field_en
				+rlimit2+rfieldvalue2;
			}
			else if(rfieldvalue1!=""&rlimit1!="")
			{
				strSql="select "+query_field+" from "+query_table+" t where t."+
				condition_field_en+rlimit1+rfieldvalue1;

			}
			else if(rfieldvalue2!=""&rlimit2!="")
			{
				strSql="select "+query_field+" from "+query_table+" t where t."+
				condition_field_en+rlimit2+rfieldvalue2;
			}		
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		else 
		{
			
			if((rfieldvalue1!=""&rlimit1!="")&(rfieldvalue2!=""&rlimit2!=""))
			{
				strSql="select t2."+main_field+" from "+condition_table+
				" t2 where t2."+condition_field_en+rlimit1+rfieldvalue1+" and t2."+condition_field_en+rlimit2+rfieldvalue2;
			}
			else if(rfieldvalue1!=""&rlimit1!="")
			{
				strSql="select t2."+main_field+" from "+condition_table+
				" t2 where t2."+condition_field_en+rlimit1+rfieldvalue1;

			}
			else if(rfieldvalue2!=""&rlimit2!="")
			{
				strSql="select t2."+main_field+" from "+condition_table+
				" t2 where t2."+condition_field_en+rlimit2+rfieldvalue2;
			}		
			List<String> list=dbService.queryDataBySql(strSql);
			int size=list.size();
			if(size==0)
			{
				return null;
			}
			List<String> resultList=new ArrayList();
			for(int i=0;i<size;i++)
			{
				String result=list.get(i);
				String[] fieldValue=result.split("；");
				int num=fieldValue.length;
				for(int j=0;j<num;j++)
				{
					String str=fieldValue[j];
					resultList.add(str);
				}
			}			
			strSql="select "+query_field+" from "+query_table+" t1 where t1."+
			foreign_field+" in(";
			int num=resultList.size();
			for(int k=0;k<num;k++)
			{
				strSql+="'"+resultList.get(k)+"',";
			}
			strSql=strSql.substring(0,strSql.length()-1);
			strSql+=")";
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		return guanxianlists;
		//if(query_table.equals("PTEM_TEST_TASK")) //表1 检验检测任务表中的一条记录的多个管线以“；”分隔。
		//{
		//	guanxianlists=splitPipeLine(guanxianlists);
		//}
	}
	
	public List<String> getListByAutosearchDate(String dfieldname,
			String dfieldvalue1,String dfieldvalue2,String owner) throws IOException{
		List<String> guanxianlists=null;
		String strSql="select t.QUERY_TABLE,t.QUERY_FIELD," +
		"t.CONDITION_TABLE,t.CONDITION_FIELD_EN," +
		"MAIN_FIELD,FOREIGN_FIELD from PTEM_SEARCH_DATE t " +
		"where t.CONDITION_FIELD_EN='"+dfieldname+
		"'and t.OWNER='"+owner+"'";
		List<Object[]> objs=dbService.queryDataBySql(strSql);
		if(objs.size()==0)
		{
			return null;
		}
		Object[] obj=new Object[6];
		String query_table="";
		String query_field="";
		String condition_table="";
		String condition_field_en="";
		String main_field="";
		String foreign_field="";
		obj=objs.get(0);
		if(obj[0]!=null)
		{
			query_table=obj[0].toString();
		}
		if(obj[1]!=null)
		{
			query_field=obj[1].toString();
		}
		if(obj[2]!=null)
		{
			condition_table=obj[2].toString();
		}
		if(obj[3]!=null)
		{
			condition_field_en=obj[3].toString();
		}	
		if(obj[4]!=null)
		{
			main_field=obj[4].toString();
		}
		if(obj[5]!=null)
		{
			foreign_field=obj[5].toString();
		}
		if(main_field.equals("")||foreign_field.equals(""))
		{
			strSql="select "+query_field+" from "+query_table+" t where t."+
			condition_field_en+" between to_date('"+ dfieldvalue1+
			"','YYYY/MM/DD') and to_date('"+dfieldvalue2+"','YYYY/MM/DD')";
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		else 
		{
			strSql="select t2."+main_field+" from "+condition_table+
			" t2 where t2."+condition_field_en+" between to_date('"+ dfieldvalue1+
			"','YYYY/MM/DD') and to_date('"+dfieldvalue2+"','YYYY/MM/DD')";
			List<String> list=dbService.queryDataBySql(strSql);
			int size=list.size();
			if(size==0)
			{
				return null;
			}
			List<String> resultList=new ArrayList();
			for(int i=0;i<size;i++)
			{
				String result=list.get(i);
				String[] fieldValue=result.split("；");
				int num=fieldValue.length;
				for(int j=0;j<num;j++)
				{
					String str=fieldValue[j];
					resultList.add(str);
				}
			}			
			strSql="select "+query_field+" from "+query_table+" t1 where t1."+
			foreign_field+" in(";
			int num=resultList.size();
			for(int k=0;k<num;k++)
			{
				strSql+="'"+resultList.get(k)+"',";
			}
			strSql=strSql.substring(0,strSql.length()-1);
			strSql+=")";
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		return guanxianlists;
		//if(query_table.equals("PTEM_TEST_TASK")) //表1 检验检测任务表中的一条记录的多个管线以“；”分隔。
		//{
		//	guanxianlists=splitPipeLine(guanxianlists);
		//}
	}
	
	public String getListByAutosearchKeyword(String kfieldname,
			String kfieldvalue,String owner) throws IOException{
		List<String> guanxianlists=null;
		String resSql=null;
		String strSql="select t.QUERY_TABLE,t.QUERY_FIELD," +
		"t.CONDITION_TABLE,t.CONDITION_FIELD_EN," +
		"MAIN_FIELD,FOREIGN_FIELD from PTEM_SEARCH_KEYWORD t " +
		"where t.CONDITION_FIELD_EN='"+kfieldname+
		"'and t.OWNER='"+owner+"'";
		List<Object[]> objs=dbService.queryDataBySql(strSql);
		if(objs.size()==0)
		{
			return null;
		}
		Object[] obj=new Object[6];
		String query_table="";
		String query_field="";
		String condition_table="";
		String condition_field_en="";
		String main_field="";
		String foreign_field="";
		obj=objs.get(0);
		if(obj[0]!=null)
		{
			query_table=obj[0].toString();
		}
		if(obj[1]!=null)
		{
			query_field=obj[1].toString();
		}
		if(obj[2]!=null)
		{
			condition_table=obj[2].toString();
		}
		if(obj[3]!=null)
		{
			condition_field_en=obj[3].toString();
		}	
		if(obj[4]!=null)
		{
			main_field=obj[4].toString();
		}
		if(obj[5]!=null)
		{
			foreign_field=obj[5].toString();
		}
		if(main_field.equals("")||foreign_field.equals(""))
		{
			//判断是否包含多个
			String kfieldvalues[]=kfieldvalue.split("；");
			int num=kfieldvalues.length;
			if(num==1)
			{
				strSql="select "+query_field+" from "+query_table+" t where t."+
				condition_field_en+" in('"+kfieldvalue+"')";
				resSql=" and t."+condition_field_en+" in('"+kfieldvalue+"')";
			}
			else
			{
				strSql="select "+query_field+" from "+query_table+" t where t."+
				condition_field_en+" in(";
				for(int i=0;i<num;i++)
				{
					strSql+="'"+kfieldvalues[i]+"',";
				}	
				strSql=strSql.substring(0,strSql.length()-1);
				strSql+=")";
				//
				resSql=" and t."+condition_field_en+" in('";
				for(int i=0;i<num;i++)
				{
					resSql+="'"+kfieldvalues[i]+"',";
				}	
				resSql=resSql.substring(0,resSql.length()-1);
				resSql+=")";
			}
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		else 
		{
			//判断是否包含多个
			String kfieldvalues[]=kfieldvalue.split("；");
			int numValue=kfieldvalues.length;
			if(numValue==1)
			{
				strSql="select t2."+main_field+" from "+condition_table+
				" t2 where t2."+condition_field_en+" in('"+kfieldvalue+"')";
			}
			else
			{
				strSql="select t2."+main_field+" from "+condition_table+
				" t2 where t2."+condition_field_en+" in(";
				for(int i=0;i<numValue;i++)
				{
					strSql+="'"+kfieldvalues[i]+"',";
				}	
				strSql=strSql.substring(0,strSql.length()-1);
				strSql+=")";
			}
			List<String> list=dbService.queryDataBySql(strSql);
			int size=list.size();
			if(size==0)
			{
				return null;
			}
			List<String> resultList=new ArrayList();
			for(int i=0;i<size;i++)
			{
				String result=list.get(i);
				String[] fieldValue=result.split("；");
				int num=fieldValue.length;
				for(int j=0;j<num;j++)
				{
					String str=fieldValue[j];
					resultList.add(str);
				}
			}			
			strSql="select "+query_field+" from "+query_table+" t1 where t1."+
			foreign_field+" in(";
			resSql=" and t1."+foreign_field+" in(";
			int num=resultList.size();
			for(int k=0;k<num;k++)
			{
				strSql+="'"+resultList.get(k)+"',";
				resSql+="'"+resultList.get(k)+"',";
			}
			strSql=strSql.substring(0,strSql.length()-1);
			strSql+=")";
			resSql=resSql.substring(0,resSql.length()-1);
			resSql+=")";
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		return resSql;
		//return guanxianlists;
	}
	public List<String> getListByAutosearchSelectHas(String sfieldname,
			String sfieldvalue,String owner) throws IOException{
		List<String> guanxianlists=null;
		String strSql="select t.QUERY_TABLE,t.QUERY_FIELD," +
		"t.CONDITION_TABLE,t.CONDITION_FIELD_EN," +
		"MAIN_FIELD,FOREIGN_FIELD,t.CONDITION_TABLE_CN from PTEM_SEARCH_SELECT t " +
		"where t.CONDITION_FIELD_VALUE='"+sfieldname+"' or t.CONDITION_TABLE_CN='"+
		sfieldname+"' and t.OWNER='"+owner+"'";
		List<Object[]> objs=dbService.queryDataBySql(strSql);
		if(objs.size()==0)
		{
			return null;
		}
		Object[] obj=new Object[7];
		String query_table="";
		
		String query_field="";
		String condition_table="";
		String condition_table_cn="";
		String condition_field_en="";
		String main_field="";
		String foreign_field="";
		String condition_field_value="";
		obj=objs.get(0);
		if(obj[0]!=null)
		{
			query_table=obj[0].toString();
		}
		if(obj[1]!=null)
		{
			query_field=obj[1].toString();
		}
		if(obj[2]!=null)
		{
			condition_table=obj[2].toString();
		}
		if(obj[3]!=null)
		{
			condition_field_en=obj[3].toString();
		}	
		if(obj[4]!=null)
		{
			main_field=obj[4].toString();
		}
		if(obj[5]!=null)
		{
			foreign_field=obj[5].toString();
		}
		if(obj[6]!=null)
		{
			condition_table_cn=obj[6].toString();
		}
		
		if(main_field.equals("")||foreign_field.equals(""))
		{
			if(condition_field_en.equals(""))
			{
				return null;
			}
			else
			{
				strSql="select "+query_field+" from "+query_table+" t where t."+
				condition_field_en+" ='"+sfieldname+"'";
			}		
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		else 
		{
			if(condition_field_en.equals(""))
			{
				strSql="select t2."+main_field+" from "+condition_table+
				" t2";
			}
			else
			{
				strSql="select t2."+main_field+" from "+condition_table+
				" t2 where t2."+condition_field_en+" ='"+sfieldname+"'";
			}
			
			List<String> list=dbService.queryDataBySql(strSql);
			int size=list.size();
			if(size==0)
			{
				return null;
			}
			List<String> resultList=new ArrayList();
			for(int i=0;i<size;i++)
			{
				String result=list.get(i);
				if(result==null)
				{
					continue;
				}
				String[] fieldValue=result.split("；");
				int num=fieldValue.length;
				for(int j=0;j<num;j++)
				{
					String str=fieldValue[j];
					resultList.add(str);
				}
			}			
			strSql="select "+query_field+" from "+query_table+" t1 where t1."+
			foreign_field+" "+sfieldvalue+"(";
			int num=resultList.size();
			if(num==0)
			{
				return null;
			}
			for(int k=0;k<num;k++)
			{
				strSql+="'"+resultList.get(k)+"',";
			}
			strSql=strSql.substring(0,strSql.length()-1);
			strSql+=")";
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		return guanxianlists;
		//if(query_table.equals("PTEM_TEST_TASK")) //表1 检验检测任务表中的一条记录的多个管线以“；”分隔。
		//{
		//	guanxianlists=splitPipeLine(guanxianlists);
		//}
	}
	
	public List<String> getListByAutosearchSelect(String sfieldname,
			String sfieldvalue,String owner) throws IOException{
		List<String> guanxianlists=null;
		String strSql="select t.QUERY_TABLE,t.QUERY_FIELD," +
		"t.CONDITION_TABLE,t.CONDITION_FIELD_EN," +
		"MAIN_FIELD,FOREIGN_FIELD from PTEM_SEARCH_SELECT t " +
		"where t.DICTIONARY_TABLE='"+sfieldname+
		"'and t.OWNER='"+owner+"'";
		List<Object[]> objs=dbService.queryDataBySql(strSql);
		if(objs.size()==0)
		{
			return null;
		}
		Object[] obj=new Object[6];
		String query_table="";
		String query_field="";
		String condition_table="";
		String condition_field_en="";
		String main_field="";
		String foreign_field="";
		obj=objs.get(0);
		if(obj[0]!=null)
		{
			query_table=obj[0].toString();
		}
		if(obj[1]!=null)
		{
			query_field=obj[1].toString();
		}
		if(obj[2]!=null)
		{
			condition_table=obj[2].toString();
		}
		if(obj[3]!=null)
		{
			condition_field_en=obj[3].toString();
		}	
		if(obj[4]!=null)
		{
			main_field=obj[4].toString();
		}
		if(obj[5]!=null)
		{
			foreign_field=obj[5].toString();
		}
		if(main_field.equals("")||foreign_field.equals(""))
		{
			//判断是否包含多个
			String sfieldvalues[]=sfieldvalue.split("\\,");
			int num=sfieldvalues.length;
			if(num==1)
			{
				strSql="select "+query_field+" from "+query_table+" t where t."+
				condition_field_en+" in('"+sfieldvalue+"')";
			}
			else
			{
				strSql="select "+query_field+" from "+query_table+" t where t."+
				condition_field_en+" in(";
				for(int i=0;i<num;i++)
				{
					strSql+="'"+sfieldvalues[i]+"',";
				}	
				strSql=strSql.substring(0,strSql.length()-1);
				strSql+=")";
			}			
//			strSql="select "+query_field+" from "+query_table+" t where t."+
//			condition_field_en+" in('"+sfieldvalue+"')";
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		else 
		{
			//判断是否包含多个
			String sfieldvalues[]=sfieldvalue.split("\\,");
			int numValue=sfieldvalues.length;
			if(numValue==1)
			{
				strSql="select t2."+main_field+" from "+condition_table+
				" t2 where t2."+condition_field_en+" in('"+sfieldvalue+"')";
			}
			else
			{
				strSql="select t2."+main_field+" from "+condition_table+
				" t2 where t2."+condition_field_en+" in(";			
				for(int i=0;i<numValue;i++)
				{
					strSql+="'"+sfieldvalues[i]+"',";
				}	
				strSql=strSql.substring(0,strSql.length()-1);
				strSql+=")";
			}			
			strSql="select t2."+main_field+" from "+condition_table+
			" t2 where t2."+condition_field_en+" in('"+sfieldvalue+"')";
			List<String> list=dbService.queryDataBySql(strSql);
			int size=list.size();
			if(size==0)
			{
				return null;
			}
			List<String> resultList=new ArrayList();
			for(int i=0;i<size;i++)
			{
				if(list.get(i)==null)
				{
					continue;
				}
				String result=list.get(i);
				String[] fieldValue=result.split("；");
				int num=fieldValue.length;
				for(int j=0;j<num;j++)
				{
					String str=fieldValue[j];
					resultList.add(str);
				}
			}			
			if(resultList.size()==0)
			{
				return null;
			}
			strSql="select "+query_field+" from "+query_table+" t1 where t1."+
			foreign_field+" in(";
			int num=resultList.size();
			for(int k=0;k<num;k++)
			{
				strSql+="'"+resultList.get(k)+"',";
			}
			strSql=strSql.substring(0,strSql.length()-1);
			strSql+=")";
			guanxianlists = dbService.queryDataBySql(strSql);
		}
		return guanxianlists;
		//if(query_table.equals("PTEM_TEST_TASK")) //表1 检验检测任务表中的一条记录的多个管线以“；”分隔。
		//{
		//	guanxianlists=splitPipeLine(guanxianlists);
		//}
	}
	
//	public List<String> getListByAutosearch() throws IOException{	
//		String owner=getRequest().getParameter("owner");
//		//关键字查询
//		String kfieldname= getRequest().getParameter("kfieldname");
//		String kfieldvalue=getRequest().getParameter("kfieldvalue");
//	    //kfieldvalue = java.net.URLDecoder.decode(kfieldvalue,"UTF-8");
//		//选择查询
//		String sfieldname=getRequest().getParameter("sfieldname");
//		String sfieldvalue=StringUtil.encodingUrl(getRequest().getParameter("sfieldvalue"));			
//		//区间查询
//		String rfieldname=getRequest().getParameter("rfieldname");
//		String rfieldvalue1=getRequest().getParameter("rfieldvalue1");
//		String rlimit1=getRequest().getParameter("rlimit1");
//		String rfieldvalue2=getRequest().getParameter("rfieldvalue2");
//		String rlimit2=getRequest().getParameter("rlimit2");		
//		//日期查询
//		String dfieldname=getRequest().getParameter("dfieldname");
//		String dfieldvalue1=getRequest().getParameter("dfieldvalue1");
//		String dfieldvalue2=getRequest().getParameter("dfieldvalue2");	
//		String searchSql="";
//		List<String> guanxianlists=null;
//		//关键字查询
//		if(kfieldname!=""&kfieldvalue!="") 
//		{
//			guanxianlists=getListByAutosearchKeyword(kfieldname,kfieldvalue,owner);
//		}
//		//选择查询
//		if(sfieldname!=""&sfieldvalue!="") 
//		{		
//			String dictionaryTableName="";
//			int length=sfieldname.length();
//			if(length<9)
//			{
//				dictionaryTableName="PTEM_TYPE_HAS";
//			}
//			else
//			{
//				String temp=sfieldname.substring(0, 9);
//				if(temp.equals("PTEM_TYPE")==false)
//				{
//					dictionaryTableName="PTEM_TYPE_HAS";
//				}
//			}
//			if(dictionaryTableName.equals("PTEM_TYPE_HAS"))
//			{
//				List<String> selList=getListByAutosearchSelectHas(sfieldname,sfieldvalue,owner);
//				if(guanxianlists==null)
//				{
//					guanxianlists=selList;
//				}
//				else {
//					guanxianlists.retainAll(selList);
//				}
//			}
//			else
//			{
//				List<String> selList=getListByAutosearchSelect(sfieldname,sfieldvalue,owner);
//				if(guanxianlists==null)
//				{
//					guanxianlists=selList;
//				}
//				else {
//					guanxianlists.retainAll(selList);
//				}
//			}
//			
//		}
//		//区间查询
//		if(rfieldname!=""&((rfieldvalue1!=""&&rlimit1!="")||(rfieldvalue2!=""&&rlimit2!="")))
//		{
//			List<String> rList=getListByAutosearchRangeMulti(rfieldname,rfieldvalue1,rlimit1,
//					rfieldvalue2,rlimit2,owner);
//			if(guanxianlists==null)
//			{
//				guanxianlists=rList;
//			}
//			else {
//				guanxianlists.retainAll(rList);
//			}
//		}
//		//日期查询
//		if(dfieldname!=""&(dfieldvalue1!=""&dfieldvalue2!="")) 
//		{		
//			List<String> dList=getListByAutosearchDate(dfieldname,dfieldvalue1,dfieldvalue2,owner);
//			if(guanxianlists==null)
//			{
//				guanxianlists=dList;
//			}
//			else {
//				guanxianlists.retainAll(dList);
//			}
//		}
//		return guanxianlists;
//	}
//	
	public PageResult queryPipeLineList(Map filterMap){	
		String pipelinenos=filterMap.get("pipelinenos").toString();
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		countString.append("select count(*) from ptem_pipeline t  where 1=1");
		countString.append(" and t.pipelineno in(");
		countString.append(pipelinenos);
		countString.append(")");
		queryString.append("select T.ID,T.PIPELINENO,T.PROJECTNO,T.DOCUMENTNO," +
				"T.PROJECTNAME,T.MEDIA,T.PRESSURELEVEL,T.TSGPRESSURELEVEL," +
				"T.MANAGESTYLE,T.MANAGEUNIT,T.MANAGEDEPARTMENT,T.PIPETYPE," +
				"T.PAVEMODE,T.MATERIAL,T.MATERIALMARK,T.DIAMETER,T.OUTERDIAMETER," +
				"T.THICKNESS,T.LENGTH,T.DESIGNPRESSURE,T.DESIGNTEMPERATURE," +
				"T.COATINGTYPE,T.COATINGLEVEL,T.CPTYPE,T.SIGNEDUNIT,T.SIGNED,T.REMARK" +
				" from ptem_pipeline T  where 1=1 ");
		queryString.append(" and t.pipelineno in(");
		queryString.append(pipelinenos);
		queryString.append(")");
		//queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);	
	}
}
